﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.Services;
using Public;
using Model;

namespace WebsiteAdmin.Wilson.Focus.Handler
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class Update : IHttpHandler
    {
        protected string responseText = "";
        protected string strCon = "";
        FocusSlide focusSlide = new FocusSlide();  //创建幻灯片对象
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.ContentType = "text/plain";
            if (Cookie.AdminLoginName != null || Cookie.AdminLoginName != "")    //登陆名判断
            {
                strCon = Global.ConnWilson;
                InitDate(context);
                int result = UpdateFocusByPKID(focusSlide, strCon);
                if (result == 1)
                {
                    responseText = "{\"Done\": \"Success\"}";
                }
                else
                {
                    responseText = "{\"Done\":\"Failed\"}";
                }
                context.Response.Write(responseText);
            }
            else
            {
                context.Response.Clear();
                context.Response.CacheControl = "no-cache";
                context.Response.Write("");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        //初始化数据
        protected void InitDate(HttpContext context)
        {
            focusSlide.PKID = Convert.ToInt32(context.Request["pkid"]);
            focusSlide.FocusTitle = context.Request["title"];
            focusSlide.Summary = context.Request["summary"];
            focusSlide.ImgURL = context.Request["imgURL"];
            focusSlide.LinkURL = context.Request["linkURL"];
            focusSlide.SortBy = Convert.ToInt32(context.Request["sort"]);
            focusSlide.StartDate = Convert.ToDateTime(context.Request["startDate"]);
            focusSlide.EndDate = Convert.ToDateTime(context.Request["endDate"]);
        }

        //修改Focus  根据PKID
        protected int UpdateFocusByPKID(FocusSlide fs, string strCon)
        {
            return new Bll.FocusSlide().UpdateFocusByPKID(fs, strCon);
        }
    }
}
